package ar.com.ctrln.persistence.dao.liquidacion;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import ar.com.ctrln.persistence.dao.AbstractHibernateDao;
import ar.com.ctrln.persistence.model.liquidacion.DetalleLiquidacion;
import ar.com.ctrln.persistence.model.liquidacion.Liquidacion;

@Repository("liquidacionDao")
public class HibernateLiquidacionDao extends AbstractHibernateDao<Liquidacion>
		implements LiquidacionDao {

	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly = true)
	public List<DetalleLiquidacion> listarDetalles(long idLiquidacion) {
		Query q = getSession().createQuery(
				"Select l.detalles from Liquidacion as l where l.id = ?");
		q.setParameter(0, idLiquidacion);
		return q.list();
	}

	@Override
	@Transactional(readOnly = true)
	public Liquidacion get(Date desde, Date hasta) {
		Query q = getSession()
				.createQuery(
						"from Liquidacion as l where l.fechaDesde = ? and l.fechaHasta = ?");
		q.setParameter(0, desde);
		q.setParameter(1, hasta);
		return (Liquidacion) q.uniqueResult();
	}

	@Override
	@Transactional(readOnly = true)
	public Liquidacion get(int mes, int anio) {
		Query q = getSession().createQuery(
				"from Liquidacion as l where l.mes = ? and l.anio = ?");
		q.setParameter(0, mes);
		q.setParameter(1, anio);
		return (Liquidacion) q.uniqueResult();
	}
}
